﻿using infoMECHANICA.NHibernateORM.TestMappings;
using NHibernate.Criterion;

namespace infoMECHANICA.NHibernateORM.ExampleProgram
{
    /// <summary>
    /// See http://www.codeplex.com/nhcb/Wiki/View.aspx?title=MIXED_QUERIES&referringTitle=Home for details
    /// </summary>
    public class Example5 : IExample
    {
        #region IExample Members

        public string Title
        {
            get { return "Example 5 - Mixed queries"; }
        }

        public DetachedCriteria ComposeCriteria()
        {
            // business restrictions of average salary of employee from "Groogle" company
            EmployeeRec avgEmployeeRec = new EmployeeRec();
            avgEmployeeRec.Company.Name.SetEq("Groogle");

            // business restrictions for employees (all companies) whose salary 
            // is greater than "average employee salary"
            EmployeeRec overAvgSalaryEmployeeRec = new EmployeeRec();
            overAvgSalaryEmployeeRec.Salary.SetGe(avgEmployeeRec.Salary.RecordedProjectionAvg);

            return overAvgSalaryEmployeeRec.BuildCriteria();
        }

        #endregion
    }
}
